package com.xy.utils;

/**
 * response
 * @param <T>
 */
public class Response<T> {
    private T res;
    private int code;

    public Response(int code, T res) {
        this.res = res;
        this.code = code;
    }

    public T getRes() {
        return this.res;
    }

    public int getCode() {
        return this.code;
    }

    public void setRes(final T res) {
        this.res = res;
    }

    public void setCode(final int code) {
        this.code = code;
    }

    @Override
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Response)) {
            return false;
        } else {
            Response<?> other = (Response)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object thisRes = this.getRes();
                Object otherRes = other.getRes();
                if (thisRes == null) {
                    if (otherRes == null) {
                        return this.getCode() == other.getCode();
                    }
                } else if (thisRes.equals(otherRes)) {
                    return this.getCode() == other.getCode();
                }

                return false;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof Response;
    }

    @Override
    public int hashCode() {
        int result = 1;
        Object res = this.getRes();
        result = result * 59 + (res == null ? 43 : res.hashCode());
        result = result * 59 + this.getCode();
        return result;
    }

    @Override
    public String toString() {
        return "Response(res=" + this.getRes() + ", code=" + this.getCode() + ")";
    }
}
